package com.ogawa.project6602.viewmodel

import androidx.lifecycle.MutableLiveData
import com.github.mikephil.charting.data.Entry
import com.ogawa.base.base.BaseViewModel
import com.ogawa.base.bean.LoadState
import com.ogawa.base.constants.Constants.Companion.NET_DEF_PLATFORM
import com.ogawa.project6602.service.HealthApiService
import com.ogawa.projectcommon.constants.Constant.TYPECODE_EC_6602
import com.ogawa.projectcommon.network.RetrofitManager
import com.ogawa.projectcommon.utils.ProjectSpUtils
import com.ogawa.projectcommon.utils.launch

class HealthIndexModel : BaseViewModel() {
    var suantongEntry = ArrayList<Entry>()
    var huoliEntry = ArrayList<Entry>()
    var times = ArrayList<String>()
    private val api = RetrofitManager.INSTANCE.createService(HealthApiService::class.java)
    var timeFrame = "0"
    var getDataEnd = MutableLiveData<Boolean>()
    var suantongCheckIng = MutableLiveData<Boolean>()
    init {
        getDataEnd.value = false
        suantongCheckIng.value = false
    }
    fun getReport() {
        launch({
            loadState.value = LoadState.Loading("")
            val userInfo = ProjectSpUtils.getUserInfo()
//            val baseResponseBean =
//                api.getHealthServiceReportStatistic(
//                    userInfo.user.id,
//                    NET_DEF_PLATFORM,
//                    timeFrame,
//                    TYPECODE_EC_6602
//                )
//            val historyReportList = baseResponseBean.data

            var _suantongEntryList = ArrayList<Entry>()
            var _huoliEntryList = ArrayList<Entry>()


            _suantongEntryList.add(Entry(1f, 50f))
            _suantongEntryList.add(Entry(2f, 66f))
            _suantongEntryList.add(Entry(3f, 120f))
            _suantongEntryList.add(Entry(4f, 30f))
            _suantongEntryList.add(Entry(5f, 10f))
            _suantongEntryList.add(Entry(6f, 110f))
            _suantongEntryList.add(Entry(7f, 30f))
            _suantongEntryList.add(Entry(7f, 160f))
            _suantongEntryList.add(Entry(9f, 30f))

            _huoliEntryList.add(Entry(1f, 50f*2f))
            _huoliEntryList.add(Entry(2f, 66f*2f))
            _huoliEntryList.add(Entry(3f, 120f*2f))
            _huoliEntryList.add(Entry(4f, 30f*2f))
            _huoliEntryList.add(Entry(5f, 10f*2f))
            _huoliEntryList.add(Entry(6f, 110f*2f))
            _huoliEntryList.add(Entry(7f, 30f*2f))
            _huoliEntryList.add(Entry(7f, 160f*2f))
            _huoliEntryList.add(Entry(9f, 30f*2f))
            times.clear()
            for (i in 0..10){
                times.add("${i}")
            }

            suantongEntry = _suantongEntryList
            huoliEntry = _huoliEntryList
            getDataEnd.value = true

        }, { loadState.value = LoadState.Fail(it.message ?: "") }, {})
    }

}